package com.example.quartz.jobBean;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

@Slf4j
public class TestJob implements Job {

    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("注入成功 : {}", objectMapper.getClass().getName());
        Map<String, Object> ret = jobExecutionContext.getMergedJobDataMap();
        try {
            log.info("job数据 : {}", objectMapper.writeValueAsString(ret));
        } catch (JsonProcessingException e) {
            log.error("job数据 转换失败", e);
        }
    }
}
